package 课本的项目.第二章_电影院售票系统;

import java.util.Scanner;

public class moviesystem {
    public static void main(String[] args) {
        int arr[][] = new int[8][10];
        int money = 0;
        Scanner sc = new Scanner(System.in);
        boolean res = true;


        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++) {
                arr[i][j] = 0;
            }
        }

        while (res) {
            System.out.println("------电影院售票系统--------");
            System.out.println("-----欢迎进入影院购票系统，本影院座位有8排10列，共80个座位（其中0为空座位，1为已购座位）------");
            System.out.println("注意：本影院座位的不同区域价格不同，其中前二排为45元，中间三排为50元，后三排为40元");
            System.out.println("当前电影院座位状态：");

            for (int i = 0; i < arr.length; i++) {
                for (int j = 0; j < arr[i].length; j++) {
                    System.out.print(arr[i][j] + "  ");
                }
                System.out.println();
            }

            System.out.println("请输入您要购买的座位号（格式：排 列，例如：1 2）：");
            int hang = sc.nextInt();
            int lie = sc.nextInt();


            if (hang < 1 || hang > 8 || lie < 1 || lie > 10) {
                System.out.println("座位号无效，请重新输入！");
                continue;
            }

            if (arr[hang - 1][lie - 1] == 1) {
                System.out.println("该座位已被购买，请选择其他座位！");
                continue;
            }

            arr[hang - 1][lie - 1] = 1;


            int price;
            if (hang <= 2) {
                price = 45;
            } else if (hang <= 5) {
                price = 50;
            } else {
                price = 40;
            }
            money += price;


            int remainingSeats = 0;
            for (int i = 0; i < arr.length; i++) {
                for (int j = 0; j < arr[i].length; j++) {
                    if (arr[i][j] == 0) {
                        remainingSeats++;
                    }
                }
            }

            System.out.println("剩余座位数：" + remainingSeats);
            System.out.println("当前电影院座位状态：");
            for (int i = 0; i < arr.length; i++) {
                for (int j = 0; j < arr[i].length; j++) {
                    System.out.print(arr[i][j] + "  ");
                }
                System.out.println();
            }

            System.out.println("是否继续买票（输入true为是，输入false表示不继续）：");
            res = sc.nextBoolean();
        }

        System.out.println("您此次购买电影票花了：" + money + "元");
        sc.close();
    }
}
